<?php

namespace app\admin\service;

use app\common\BaseHelper as Helper;
use app\admin\model\Meeting as MeetingMdl;

use think\Db;
use think\Exception;

class Meeting
{

    /**
     * 生成会议签到二维码
     *
     * @return bool|string
     */
    public static function createMeetingCode($meetingId, $townId){
        $businessId = db('townprogram')->where(['townId' => $townId])->value('id');
        // 接口调用凭据
        $access_token = json_decode(Helper::curlGet(config('miniprogram.wx_domain').'/api/WechatOpenApi/getAuthorizerToken?b=' . $businessId . '&isRefresh=true'),true);
        $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' . $access_token;
        $postData["scene"] = $meetingId;
        $postData["path"] = "pages/home/Home";
        //$postData["page"] = "pages/home/Home";

        $result = Helper::curlPost($url, json_encode($postData));
        if(json_decode($result,true)['errcode']){
            return false;
        }
        $upload = config('path.Upload_path');
        $savepath = 'meeting/' . date('Ymd');
        $filepath = $upload . $savepath;
        if(!file_exists($filepath)){
            mkdir($filepath, 0777, true);
        }
        $filename = Helper::getUUID() . '.png';

        file_put_contents($filepath . '/' . $filename, $result);

        return $savepath . '/' . $filename;
    }

}